package com.foo.cms.service.impl;

import com.foo.cms.service.BaseService;
import com.foo.cms.service.RecommendService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: LZS
 * Date: 12-6-25
 * Time: 下午10:51
 * To change this template use File | Settings | File Templates.
 */
@Service
public class RecommendServiceImpl extends BaseService implements RecommendService {
    private static final Logger logger = LoggerFactory.getLogger(ArticleServiceImpl.class);

    @Override
    public Map<Object, Object> listRec() {
        Map<Object, Object> result = new HashMap<Object, Object>();
        String sql = "select * from dt_recommend";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, new HashMap<String, Object>());
        for (Map<String, Object> map : list) {
            result.put(map.get("numrecommendid"), map.get("vc2recommendname"));
        }
        return result;
    }

    public Map<Object, Object> list(String id) {
        Map<Object, Object> recommnetMap = new HashMap<Object, Object>();
        String sql = "select r.numrecommendid , r.numartrecoid from dt_article a , dt_article_recommend r where a.numarticleid = r.numarticleid and r.numarticleid = " + id;
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, new HashMap<String, Object>());
        for (Map<String, Object> map : list) {
            Object recommendId = map.get("numrecommendid");
            Object artRecoId = map.get("numartrecoid");
            recommnetMap.put(recommendId, artRecoId);
            logger.info("id = " + id + " , recommendId = " + recommendId + " , artRecoId = " + artRecoId);
        }

        return recommnetMap;
    }
}
